package com.probox.common.entity.service.customer.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.probox.common.core.utils.StringUtils;
import com.probox.common.entity.domain.customer.CustomerBehavior;
import com.probox.common.entity.mapper.customer.CustomerBehaviorMapper;
import com.probox.common.entity.service.customer.ICustomerBehaviorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * 用户行为日志Service业务层处理
 *
 * @author usoft
 * @date 2022-09-30
 */
@Service
@Transactional
public class CustomerBehaviorServiceImpl extends ServiceImpl<CustomerBehaviorMapper, CustomerBehavior> implements ICustomerBehaviorService {
    @Autowired
    private CustomerBehaviorMapper customerBehaviorMapper;


    /**
     * 查询用户行为日志
     *
     * @param behaviorId 用户行为日志ID
     * @return 用户行为日志
     */
    @Override
    public CustomerBehavior selectCustomerBehaviorById(Long behaviorId) {
        return this.getById(behaviorId);
    }

    /**
     * 查询用户行为日志列表
     *
     * @param customerBehavior 用户行为日志
     * @return 用户行为日志
     */
    @Override
    public List<CustomerBehavior> queryList(CustomerBehavior customerBehavior) {
        QueryWrapper<CustomerBehavior> queryWrapper = Wrappers.query();
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getBehaviorId())) && customerBehavior.getBehaviorId() != null) {
            queryWrapper.eq("behavior_id", customerBehavior.getBehaviorId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getAccountId())) && customerBehavior.getAccountId() != null) {
            queryWrapper.eq("account_id", customerBehavior.getAccountId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getNickName())) && customerBehavior.getNickName() != null) {
            queryWrapper.eq("nick_name", customerBehavior.getNickName());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getHeadImage())) && customerBehavior.getHeadImage() != null) {
            queryWrapper.eq("head_image", customerBehavior.getHeadImage());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getBehaviorType())) && customerBehavior.getBehaviorType() != null) {
            queryWrapper.eq("behavior_type", customerBehavior.getBehaviorType());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getBehaviorLabel())) && customerBehavior.getBehaviorLabel() != null) {
            queryWrapper.eq("behavior_label", customerBehavior.getBehaviorLabel());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getPageName())) && customerBehavior.getPageName() != null) {
            queryWrapper.eq("page_name", customerBehavior.getPageName());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getPageUrl())) && customerBehavior.getPageUrl() != null) {
            queryWrapper.eq("page_url", customerBehavior.getPageUrl());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getBusinessType())) && customerBehavior.getBusinessType() != null) {
            queryWrapper.eq("business_type", customerBehavior.getBusinessType());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getBusinessTypeLabel())) && customerBehavior.getBusinessTypeLabel() != null) {
            queryWrapper.eq("business_type_label", customerBehavior.getBusinessTypeLabel());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getBusinessId())) && customerBehavior.getBusinessId() != null) {
            queryWrapper.eq("business_id", customerBehavior.getBusinessId());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getBusinessName())) && customerBehavior.getBusinessName() != null) {
            queryWrapper.eq("business_name", customerBehavior.getBusinessName());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getBusinessTag())) && customerBehavior.getBusinessTag() != null) {
            queryWrapper.eq("business_tag", customerBehavior.getBusinessTag());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getDataStatus())) && customerBehavior.getDataStatus() != null) {
            queryWrapper.eq("data_status", customerBehavior.getDataStatus());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getCreateUser())) && customerBehavior.getCreateUser() != null) {
            queryWrapper.eq("create_user", customerBehavior.getCreateUser());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getCreateName())) && customerBehavior.getCreateName() != null) {
            queryWrapper.eq("create_name", customerBehavior.getCreateName());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getUpdateUser())) && customerBehavior.getUpdateUser() != null) {
            queryWrapper.eq("update_user", customerBehavior.getUpdateUser());
        }
        if (StringUtils.isNotEmpty(String.valueOf(customerBehavior.getUpdateName())) && customerBehavior.getUpdateName() != null) {
            queryWrapper.eq("update_name", customerBehavior.getUpdateName());
        }
        return customerBehaviorMapper.selectList(queryWrapper);
    }

    /**
     * 新增用户行为日志
     *
     * @param customerBehavior 用户行为日志
     * @return 结果
     */
    @Override
    public boolean insertCustomerBehavior(CustomerBehavior customerBehavior) {

        return this.save(customerBehavior);

    }

    /**
     * 修改用户行为日志
     *
     * @param customerBehavior 用户行为日志
     * @return 结果
     */
    @Override
    public boolean updateCustomerBehavior(CustomerBehavior customerBehavior) {

        return this.updateById(customerBehavior);
    }

    /**
     * 批量删除用户行为日志
     *
     * @param behaviorIds 需要删除的用户行为日志ID
     * @return 结果
     */
    @Override
    public boolean deleteCustomerBehaviorByIds(Long[] behaviorIds) {
        return this.removeByIds(Arrays.asList(behaviorIds));
    }


}
